﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using YanZhiwei.DotNet2.Utilities.Models;
using YanZhiwei.DotNet2.Utilities.Tests.Model;

namespace YanZhiwei.DotNet2.Utilities.Common.Tests
{
    [TestClass()]
    public class ReflectHelperTests
    {
        [TestMethod()]
        public void PublicInstancePropertiesEqualTest()
        {
            Person _personA = new Person() { Name = "YanZhiwei", Age = 10, Address = "shanghai" };
            Person _personB = new Person() { Name = "YanZhiwei", Age = 11, Address = "shanghai" };
            Assert.AreEqual(false, ReflectHelper.PublicInstancePropertiesEqual<Person>(_personA, _personB));
        }

        [TestMethod()]
        public void DetailedPublicInstancePropertiesEqualTest()
        {
            Person _personA = new Person() { Name = "YanZhiwei", Age = 10, Address = "shanghai" };
            Person _personB = new Person() { Name = "YanZhiwei", Age = 11, Address = "shanghai" };
            List<Variance> _difference = ReflectHelper.DetailedPublicInstancePropertiesEqual<Person>(_personA, _personB);
            Assert.AreEqual(1, _difference.Count);

        }

        [TestMethod()]
        public void DetailedPublicInstancePropertiesTest()
        {
            Person _personA = new Person() { Name = "YanZhiwei", Age = 10, Address = "shanghai" };
            List<Variance> _actual = ReflectHelper.DetailedPublicInstanceProperties<Person>(_personA, "123");
            List<Variance> _expected = new List<Variance>();
            _expected.Add(new Variance() { Key = "Name", Value = "YanZhiwei", SubKey = "123" });
            _expected.Add(new Variance() { Key = "Age", Value = 10, SubKey = "123" });
            _expected.Add(new Variance() { Key = "Address", Value = "shanghai", SubKey = "123" });
            bool _result = EntityHelper.CompareObject(_expected, _actual);
            Assert.AreEqual(true,_result);

        }
    }
}
